package com.wenx.v3system.modular.cloud.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wenx.v3system.modular.cloud.domain.po.SysRolePermission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface SysRolePermissionMapper extends BaseMapper<SysRolePermission> {
    
    /**
     * 物理删除角色的所有权限关联
     * 
     * @param roleId 角色ID
     * @return 删除的记录数
     */
    @Delete("DELETE FROM sys_role_permission WHERE role_id = #{roleId}")
    int deleteByRoleIdPhysically(@Param("roleId") Long roleId);
    
    /**
     * 物理删除指定角色的指定权限关联
     * 
     * @param roleId 角色ID
     * @param permissionIds 权限ID列表
     * @return 删除的记录数
     */
    @Delete("<script>" +
            "DELETE FROM sys_role_permission WHERE role_id = #{roleId} " +
            "AND permission_id IN " +
            "<foreach collection='permissionIds' item='permissionId' open='(' separator=',' close=')'>" +
            "#{permissionId}" +
            "</foreach>" +
            "</script>")
    int deleteByRoleIdAndPermissionIdsPhysically(@Param("roleId") Long roleId, @Param("permissionIds") List<Long> permissionIds);
    
    /**
     * 物理删除权限的所有角色关联
     * 
     * @param permissionId 权限ID
     * @return 删除的记录数
     */
    @Delete("DELETE FROM sys_role_permission WHERE permission_id = #{permissionId}")
    int deleteByPermissionIdPhysically(@Param("permissionId") Long permissionId);
}